<template>
	<view class="my-goods">
		<view class="goods-box">
			<!-- 左边图片区 -->
			<view class="goods-content-left">
				<radio :checked="goods.goods_state" v-if="showRadio" @click="radioClickE"></radio>
				<image :src="goods.goods_small_logo || defaultPic" class="goods-pic"></image>
			</view>
			<!-- 右边文字区域 -->
			<view class="goods-content-rigth">
				<view class="goods-text">
					{{goods.goods_name}}
				</view>
				<view class="priceANDnum">
					<text>￥{{goods.goods_price | toFixed}}</text>
					<uni-number-box :min="1" :value="goods.goods_count" v-if="showNum" @change="numChangeE">
					</uni-number-box>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "my_goods",
		data() {
			return {
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},

		props: {
			goods: {
				type: Object,
				default: {}
			},

			showRadio: {
				type: Boolean,
				default: false
			},

			showNum: {
				type: Boolean,
				default: false
			}
		},

		filters: {
			toFixed(num) {
				return Number(num).toFixed(2)
			}
		},

		methods: {
			radioClickE() {
				this.$emit('radio-change', {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state
				})
			},

			numChangeE(val) {
				this.$emit('num-change', {
					goods_id: this.goods.goods_id,
					goods_count: +val
				})
			}
		}

	}
</script>

<style lang="scss">
	.goods-box {
		display: flex;
		margin: 5px 5px;
		// border: 1px solid red;
		box-shadow: 5px 5px 5px rgba(0, 0, 0, .3);
		background-color: #fff;
		box-sizing: border-box;
	}

	.goods-content-left {
		display: flex;
		align-items: center;
	}

	.goods-pic {
		width: 88px;
		height: 104px;
	}

	.goods-content-rigth {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-left: 10px;
		font-size: 12px;

		text {
			font-size: 14px;
			color: #c00000
		}

		.priceANDnum {
			display: flex;
			justify-content: space-between;
			padding-bottom: 5px;
		}
	}
</style>
